//
//  ViewController.m
//  calculate
//
//  Created by iD Student on 6/25/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    answer = nil;
    answer = nil;
    answer = nil;
    answer = nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}
-(IBAction)getNum:(id)sender{
    if(op){
        secNum=secNum*10+(float)[sender tag];
        answer.text=[NSString stringWithFormat:@"%3.2f",secNum];
        op=FALSE;
    }else{
        firstNum=firstNum*10+(float)[sender tag];
        answer.text=[NSString stringWithFormat:@"%3.2f",firstNum];
    }
}
-(IBAction)doMath:(id)sender{
    switch (operation) {
        case 0:
            answer.text=[NSString stringWithFormat:@"%3.2f",(firstNum+secNum)];
            break;
        case 1:
            answer.text=[NSString stringWithFormat:@"%3.2f",(firstNum-secNum)];
            break;
        case 2:
            answer.text=[NSString stringWithFormat:@"%3.2f",(firstNum*secNum)];
            break;
        case 3:
            answer.text=[NSString stringWithFormat:@"%3.2f",(firstNum/secNum)];
            break;
    }
}
-(IBAction)getOperation:(id)sender{
    operation= [sender tag];
    answer.text=[NSString stringWithFormat:@""];
    op=TRUE;
}
-(IBAction)clearUp:(id)sender{
    firstNum=newNum;
    secNum=newNum;
    operation=newNum;
    answer.text=[NSString stringWithFormat:@""];
}
@end
